package Error;

import interfaces.ErrorReport;

public class ScriptError implements ErrorReport {
	private String scriptLineText; 		// Text that caused error
	private String errorInformation; 	// Description of error
	private int line;					// Line in the script the text is on
	private ErrorType errorType;
	
	public ScriptError(String errorInformation, String scriptLineText, int line,
						ErrorType errorType) {
		this.scriptLineText = scriptLineText;
		this.errorInformation = errorInformation;
		this.line = line;
		this.errorType = errorType;
		
		if (scriptLineText != null && scriptLineText.length() > 14) {
			scriptLineText = scriptLineText.substring(0, 14) + "...";
		}
	}
	
	/**
	 * Return this error in message form.
	 */
	public String getErrorMessage() {
		String newline = System.getProperty("line.separator");
		
		return errorInformation + " on line " + line + "." + newline + "   \"" + scriptLineText + "\"";
	}
	
	public ErrorType getType() {
		return errorType;
	}
	
	public int getLine() {
		return line;
	}

}
